package com.example.system.controller.exam;

import com.example.common.core.controller.BaseController;
import com.example.common.core.model.R;
import com.example.common.core.model.TableDataInfo;
import com.example.system.model.exam.dto.ExamAddDTO;
import com.example.system.model.exam.dto.ExamEditDTO;
import com.example.system.model.exam.dto.ExamQueryDTO;
import com.example.system.model.exam.dto.ExamQuestAddDTO;
import com.example.system.model.exam.vo.ExamDetailVO;
import com.example.system.model.exam.vo.ExamVO;
import com.example.system.service.IExamService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能描述:
 *
 * @author Lenovo
 * @date 2025/3/23
 */
@Slf4j
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Resource
    private IExamService examService;

    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO queryDTO){
        List<ExamVO> list = examService.list(queryDTO);
        return getTableDataInfo(list);
    }

    @PostMapping("/add")
    public R<Void> add(@RequestBody ExamAddDTO examAddDTO){
        int row = examService.add(examAddDTO);
        return toResult(row);
    }

    @PostMapping("/question/add")
    public R<Void> questionAdd(@RequestBody ExamQuestAddDTO examQuestAddDTO){
        boolean result = examService.questionAdd(examQuestAddDTO);
        return toResult(result);
    }

    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId){
        ExamDetailVO result = examService.detail(examId);
        return R.ok(result);
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO){
        int row = examService.edit(examEditDTO);
        return toResult(row);
    }

    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId,Long questionId){
        log.info("接收到参数 examId:{},questionId:{}",examId,questionId);
        int row = examService.questionDelete(examId,questionId);
        return toResult(row);
    }

    @DeleteMapping("/delete")
    public R<Void> delete(Long examId){
        int row = examService.delete(examId);
        return toResult(row);
    }

    @PutMapping("/publish")
    public R<Void> publish(Long examId) {
        int row = examService.publish(examId);
        return toResult(row);
    }

    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long examId){
        int row = examService.cancelPublish(examId);
        return toResult(row);
    }
}
